package dao.impl;

import dao.DeptDao;
import org.apache.ibatis.session.SqlSession;
import pojo.Dept;
import utils.MyBatisUtil;

import java.util.List;

public class DeptDaoImpl implements DeptDao {
    @Override
    public List<Dept> findAll(Dept dept) {

        return MyBatisUtil.getSession().getMapper(DeptDao.class).findAll(dept);

    }

    public int addDept(Dept dept) {
        SqlSession session = MyBatisUtil.getSession();
        int result=session.getMapper(DeptDao.class).addDept(dept);
        session.commit();
        return result;
    }

    @Override
    public Dept findDeptById(int id) {
        return MyBatisUtil.getSession().getMapper(DeptDao.class).findDeptById(id);

    }

    @Override
    public int updateDept(Dept dept) {
        SqlSession session = MyBatisUtil.getSession();
        int result=session.getMapper(DeptDao.class).updateDept(dept);
        session.commit();
        return result;
    }

    @Override
    public int deleteDeptById(int id) {
        SqlSession session = MyBatisUtil.getSession();
        int result=session.getMapper(DeptDao.class).deleteDeptById(id);
        session.commit();
        return result;
    }

}